package handler

import (
	"github.com/gin-gonic/gin"
	"me/123/api/client"
	"me/123/api/enit/request"
	"me/123/api/enit/response"
	"me/123/common/proto/user"
)

func Login(c *gin.Context) {
	var req request.Login

	if err := c.ShouldBind(&req); err != nil {
		response.ErrorResponse(c, "参数错误", err.Error())
		return
	}

	login, err := client.Login(c, &user.LoginRequest{
		Mobile:   req.Mobile,
		Password: req.Password,
	})
	if err != nil {
		response.ErrorResponse(c, "登入失败", err.Error())
		return
	}
	response.SuccessResponse(c, "登入成功", login)
}

func CollectVoucher(c *gin.Context) {
	var req request.CollectVoucher

	if err := c.ShouldBind(&req); err != nil {
		response.ErrorResponse(c, "参数错误", err.Error())
		return
	}

	userId := c.GetUint("userId")
	login, err := client.CollectVoucher(c, &user.CollectVoucherRequest{
		UserId:    int64(userId),
		CouponsId: req.CouponsId,
	})
	if err != nil {
		response.ErrorResponse(c, "err", err.Error())
		return
	}
	response.SuccessResponse(c, "ok", login)
}
